package com.wtwd.device.controller;

import com.wtwd.device.constant.RespCode;
import com.wtwd.device.model.dto.SynchronizationHeartRateDto;
import com.wtwd.device.model.entity.DeviceBloodOxygen;
import com.wtwd.device.model.entity.DeviceHeartRate;
import com.wtwd.device.model.entity.DeviceHeartRateTotal;
import com.wtwd.device.model.vo.DeviceHeartRateTotalVo;
import com.wtwd.device.model.vo.ResultVO;
import com.wtwd.device.service.AppDeviceHeartRateService;
import com.wtwd.device.service.AppDeviceHeartRateTotalService;
import com.wtwd.device.util.DateUtils;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.text.ParseException;
import java.util.Date;
import java.util.List;

@Api(tags = "心率模块")
@RestController
@RequestMapping("/app-heartRate")
public class AppDeviceHeartRateController {


    @Resource
    private AppDeviceHeartRateTotalService appDeviceHeartRateTotalService;



    @ApiOperation("获取某一天的心率信息及心率详细信息(一般心率)")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "deviceId", value = "设备id", required = true, dataType = "long"),
            @ApiImplicitParam(name = "date", value = "日期,yyyyMMdd", required = true, dataType = "String"),
            @ApiImplicitParam(name = "id", value = "心率详细信息表主键id 默认不传查全天", required = false, dataType = "long")
    })
    @ApiResponses({@ApiResponse(code = 400, message = "参数错误")
    })
    @GetMapping("/getDayHeartRateByTime")
    public ResultVO<DeviceHeartRateTotalVo> getDayHeartRateByTime(@RequestParam String date, @RequestParam Long deviceId, @RequestParam(value = "id", required = false) Long id) {
        DeviceHeartRateTotalVo deviceHeartRateTotalVo = appDeviceHeartRateTotalService.getDayHeartRateByTime(deviceId, id, date);
        return ResultVO.success(deviceHeartRateTotalVo);
    }

    @ApiOperation(value = "根据开始日期和结束日期获取心率详细信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "deviceId", value = "设备id", required = true, dataType = "long")
            , @ApiImplicitParam(name = "startDate", value = "开始日期,yyyyMMdd", required = true, dataType = "String")
            , @ApiImplicitParam(name = "endDate", value = "结束日期,yyyyMMdd", required = true, dataType = "String")
    })
    @ApiResponses({@ApiResponse(code = 400, message = "参数错误")
    })
    @GetMapping("/getDaysHeartRateTotal")
    public ResultVO<List<DeviceHeartRateTotal>> getDaysHeartRateTotal(@RequestParam Long deviceId, @RequestParam String startDate, @RequestParam String endDate) {
        List<DeviceHeartRateTotal> deviceHeartRateTotals = appDeviceHeartRateTotalService.getDaysHeartRate(deviceId, startDate, endDate);
        return ResultVO.success(deviceHeartRateTotals);
    }


    /**
     * 同步心率数据
     *
     * @return
     */
    @ApiOperation("同步心率数据")
    @PostMapping("/synchronizationHeartRate")
    public ResultVO<List<DeviceHeartRateTotal>> synchronizationHeartRate(@RequestBody SynchronizationHeartRateDto dao) {
        List<DeviceHeartRateTotal> deviceHeartRateTotals = appDeviceHeartRateTotalService.synchronizationHeartRate(dao.getDeviceHeartRateTotalDtos());
        return ResultVO.success(deviceHeartRateTotals);
    }


}
